using System;
using System.Data;
using System.Configuration;
using System.Web;			    
using System.Drawing;	 
using System.IO;


namespace Possan.Graphics.Filters
{
	public class SkinBackground : IBaseFilter
	{
		public string ParameterDefinition
		{
			get
			{
				     return null;
			}
		}

		public int Left;
		public int Top;
		public int Right;
		public int Bottom;
		public string ImagePath;

		public string ParameterDirection
		{
			get
			{
				     return null;
			}
		}

		public SkinBackground()
		{
			Left = 5;
			Top = 5;
			Right = 5;
			Bottom = 5;
			ImagePath = "";
		}

		public Bitmap Filter(Bitmap bitmap)
		{
			Bitmap bmp2 = new Bitmap(bitmap.Width, bitmap.Height);
			bmp2.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);

			Bitmap skin = null;
			string lp = "";
			if (ImagePath != "")
			{
				if (File.Exists(ImagePath))
				{
					try
					{
						skin = (Bitmap)Bitmap.FromFile(ImagePath);
					}
					catch (Exception z)
					{     
						Logger.Error(this.GetType(), z);
					}
				}
			}

			Logger.Debug(this.GetType(), "lp=" + lp);
			Logger.Debug(this.GetType(), "skin=" + skin);
			if (skin != null)
			{
				skin.SetResolution(bitmap.HorizontalResolution, bitmap.VerticalResolution);
				Utilities.Skin9Grid(bmp2, skin, Left, Top, Right, Bottom, 0, 0, bitmap.Width, bitmap.Height);
			}



			System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp2);
			g.DrawImage(bitmap, 0, 0);

			     return bmp2;
		}		 
	}
}





